/*********************获取显示列表数据ajax调用 start*********************/
/**
*   ajax获取健康排程列表信息
*   arg  : 执行操作后要执行的函数也参数
*	page ： 当前页
*	status ： 部门在线的状态（0：未进行 1：正在进行 2：未进行）
*/

// 活动公告
function getHactivityListData(arg,page,status){
	//当前页
	page = (typeof page=="number")?page:1;
	var data_;
	$.ajax({
            url: "getHactivityList.html",
            async: true,
            data:{"page":page,"rows":"10"},
            type:"POST",
           	dataType:"json",
         	success:function(data){
           		data_ = data;
           		if(typeof(arg) != "undefined"){
	        		var func = arg[0];//取出函数
	        		if(typeof(func) == "function"){
		        		func.call(this,data_,arg);
	        		}
        		}
       		},error:function(){
        		connectionFail();
       		}
    });
   	window.pageNum = page;
}

// 健康叮咛
function getCalendarlogListData(arg,page,status){
	//当前页
	page = (typeof page=="number")?page:1;
	var data_;
	$.ajax({
            url: "getCalendarlogList.html",
            async: true,
            data:{"page":page,"rows":"10"},
            type:"POST",
           	dataType:"json",
         	success:function(data){
           		data_ = data;
           		if(typeof(arg) != "undefined"){
	        		var func = arg[0];//取出函数
	        		if(typeof(func) == "function"){
		        		func.call(this,data_,arg);
	        		}
        		}
       		},error:function(){
        		connectionFail();
       		}
    });
   	window.pageNum = page;
}

//用药提醒
function getHPMedicineSugListData(arg,page,status){
	//当前页
	page = (typeof page=="number")?page:1;
	var data_;
	$.ajax({
            url: "getHPMedicineSugList.html",
            async: true,
            data:{"page":page,"rows":"10"},
            type:"POST",
           	dataType:"json",
         	success:function(data){
           		data_ = data;
           		if(typeof(arg) != "undefined"){
	        		var func = arg[0];//取出函数
	        		if(typeof(func) == "function"){
		        		func.call(this,data_,arg);
	        		}
        		}
       		},error:function(){
        		connectionFail();
       		}
    });
   	window.pageNum = page;
}

//健康排程
function getHealthScheduleListData(arg,page,status){
	//当前页
	page = (typeof page=="number")?page:1;
	var data_;
	$.ajax({
            url: "getHealthScheduleList.html",
            async: true,
            data:{"page":page,"rows":"10"},
            type:"POST",
           	dataType:"json",
         	success:function(data){
           		data_ = data;
           		if(typeof(arg) != "undefined"){
	        		var func = arg[0];//取出函数
	        		if(typeof(func) == "function"){
		        		func.call(this,data_,arg);
	        		}
        		}
       		},error:function(){
        		connectionFail();
       		}
    });
   	window.pageNum = page;
}

// 血压查询
function getMeasempListData(arg,page,queryTime,measure_id){
	//当前页
	page = (typeof page=="number")?page:1;
	var data_;
	$.ajax({
            url: "getMeasempList.html",
            async: true,
            data:{"page":page,"rows":"10","queryTime":queryTime,"measure_id":measure_id},
            type:"POST",
           	dataType:"json",
         	success:function(data){
           		data_ = data;
           		if(typeof(arg) != "undefined"){
	        		var func = arg[0];//取出函数
	        		if(typeof(func) == "function"){
		        		func.call(this,data_,arg);
	        		}
        		}
       		},error:function(){
        		connectionFail();
       		}
    });
   	window.pageNum = page;
}

// 健康知识家
function getHPKnowledgeListData(arg,page,knowledgeType){
	//当前页
	page = (typeof page=="number")?page:1;
	var data_;
	$.ajax({
            url: "getHPKnowledgeList.html",
            async: true,
            data:{"page":page,"rows":"10","type":knowledgeType},
            type:"POST",
           	dataType:"json",
         	success:function(data){
           		data_ = data;
           		if(typeof(arg) != "undefined"){
	        		var func = arg[0];//取出函数
	        		if(typeof(func) == "function"){
		        		func.call(this,data_,arg);
	        		}
        		}
       		},error:function(){
        		connectionFail();
       		}
    });
   	window.pageNum = page;
}

// 食物卡卡
function getFoodclassListData(arg,page,status){
	//当前页
	page = (typeof page=="number")?page:1;
	var data_;
	$.ajax({
            url: "getFoodclassList.html",
            async: true,
            data:{"page":page,"rows":"12"},
            type:"POST",
           	dataType:"json",
         	success:function(data){
           		data_ = data;
           		if(typeof(arg) != "undefined"){
	        		var func = arg[0];//取出函数
	        		if(typeof(func) == "function"){
		        		func.call(this,data_,arg);
	        		}
        		}
       		},error:function(){
        		connectionFail();
       		}
    });
   	window.pageNum = page;
}

//食物卡路里
function getFoodcalorListData(arg,page,classcd,searchName){
	//当前页
	page = (typeof page=="number")?page:1;
	var data_;
	$.ajax({
            url: "getFoodcalorList.html",
            async: true,
            data:{"page":page,"rows":"12","classcd":classcd,"descr":searchName},
            type:"POST",
           	dataType:"json",
         	success:function(data){
           		data_ = data;
           		if(typeof(arg) != "undefined"){
	        		var func = arg[0];//取出函数
	        		if(typeof(func) == "function"){
		        		func.call(this,data_,arg);
	        		}
        		}
       		},error:function(){
        		connectionFail();
       		}
    });
   	window.pageNum = page;
}

// 健康手册
function getChildManualListData(arg,page,mtype){
	//当前页
	page = (typeof page=="number")?page:1;
	var data_;
	$.ajax({
            url: "getChildManualList.html",
            async: true,
            data:{"page":page,"rows":"12","mtype":mtype},
            type:"POST",
           	dataType:"json",
         	success:function(data){
           		data_ = data;
           		if(typeof(arg) != "undefined"){
	        		var func = arg[0];//取出函数
	        		if(typeof(func) == "function"){
		        		func.call(this,data_,arg);
	        		}
        		}
       		},error:function(){
        		connectionFail();
       		}
    });
   	window.pageNum = page;
}

//预约行程
function getHPProEventListData(arg,page){
	//当前页
	page = (typeof page=="number")?page:1;
	var data_;
	$.ajax({
            url: "getHPProEventList.html",
            async: true,
            data:{"page":page,"rows":"10"},
            type:"POST",
           	dataType:"json",
         	success:function(data){
           		data_ = data;
           		if(typeof(arg) != "undefined"){
	        		var func = arg[0];//取出函数
	        		if(typeof(func) == "function"){
		        		func.call(this,data_,arg);
	        		}
        		}
       		},error:function(){
        		connectionFail();
       		}
    });
   	window.pageNum = page;
}

/*********************获取显示列表数据ajax调用 end*********************/

/*********************热线聚焦页面中组织滚屏区域的列表显示 start*********************/

/*********************热线聚焦页面中组织滚屏区域的列表显示 end*********************/

//初始化显示头部栏
function initHeader($headerDiv,status){
	$headerDiv.empty();
	var header_bg_div_rollback = "";
	//显示设置
	//热线聚焦头栏
	if(status == "rxjj"){
		var	$div = $("<div class=\"header_bg_div\" align=\"center\">" +
					"	<div class=\"header_bg_div_bg\">" +
					"		<img src=\"${ctx}/lib/mobile/image/theme2/head.png\">" +
					"	</div>" +
					"	<div class=\"header_bg_div_logo\">" +
					"		<img class=\"logo_img\" src=\"${ctx}/lib/mobile/image/theme2/logo.png\">" +
					"		<a name=\"mobileHeaderTitle\" data-role=\"none\" class=\"logo_title\"></a>" +
					"	</div>" +
					"	<div class=\"header_bg_div_title\">" +
					"		<div class=\"menu_btn_12345\" data-role=\"none\" onclick=\"javascript:device.dial(function(arg){},function(arg){},'051412345');\"><img  class=\"dial_img\" src=\"../lib/mobile/image/theme2/dial.png\"><span style=\"margin-left:20px;\">12345</span></div>" +
					"	</div>" +
					"</div>");
	}
	//我的诉求头栏
	else if(status == "wdsq"){
		var	$div = $("<div class=\"header_bg_div\" align=\"center\">" +
					"	<div class=\"header_bg_div_bg\">" +
					"		<img src=\"../lib/mobile/image/theme2/head.png\">" +
					"	</div>" +
					"	<div class=\"header_bg_div_logo\">" +
					"		<img class=\"logo_img\" src=\"../lib/mobile/image/theme2/logo.png\">" +
					"		<a name=\"mobileHeaderTitle\" data-role=\"none\" class=\"logo_title\"></a>" +
					"	</div>" +
					"	<div class=\"header_bg_div_title\">" +
					"		<a class=\"menu_btn\" data-role=\"none\" href=\"mobile-onlineAccept.html\">在线受理</a>" +
					"	</div>" +
					"</div>");
	}else if(status == "menu"){
		var	$div = $("<div class=\"header_bg_div\" align=\"center\">" +
					"	<div class=\"header_bg_div_bg\">" +
					"	</div>" +
					"	<div class=\"header_bg_div_logo\">" +
					"		<a name=\"mobileHeaderTitle\" data-role=\"none\" class=\"logo_title\"></a>" +
					"	</div>" +
					"</div>");
	}else if(status == "back"){
		var	$div = $("<div class=\"header_bg_div\" align=\"center\">" +
					"	<div class=\"header_bg_div_bg\">" +
					"	</div>" +
					"	<div class=\"header_bg_div_logo\">" +
					"		<a name=\"mobileHeaderTitle\" data-role=\"none\" class=\"logo_title\"></a>" +
					"	</div>" +
					"	<div class=\"header_bg_div_title\">" +
					"		<div class=\"back_btn\" onclick=\"javascript:setTimeout(function(){window.history.back();}, 500);\"></div>" +
					"	</div>" +
					"</div>");
	}else if(status == "login"){
		var	$div = $("<div class=\"back_btn\" style=\"position: relative;height: 50px;\" onclick=\"javascript:setTimeout(function(){window.history.back();}, 500);\"></div>");
	}else if(status == "selectMonth"){
		var	$div = $("<div class=\"header_bg_div\" align=\"center\">" +
					"	<div class=\"header_bg_div_bg\">" +
					"		<img src=\"../lib/mobile/image/theme2/head.png\">" +
					"	</div>" +
					"	<div class=\"header_bg_div_logo\">" +
					"		<a name=\"mobileHeaderTitle\" data-role=\"none\" class=\"logo_title\"></a>" +
					"	</div>" +
					"	<div class=\"header_bg_div_title\">" +
					"		<div class=\"back_btn\" onclick=\"javascript:window.history.back();\"><img src=\"../lib/mobile/image/theme2/button_back.png\"><div>返回</div></div>" +
					"		<a class=\"menu_btn\" data-role=\"none\" href=\"javascript:window.history.back();\">确  定</a>" +
					"	</div>" +
					"</div>");
	}
	//部门在线
	else if(status == "bmzx"){
		var	$div = $("<div class=\"header_bg_div\" align=\"center\">" +
					"	<div class=\"header_bg_div_bg\">" +
					"		<img src=\"../lib/mobile/image/theme2/head.png\">" +
					"	</div>" +
					"	<div class=\"header_bg_div_logo\">" +
					"		<a name=\"mobileHeaderTitle\" data-role=\"none\" class=\"logo_title\"></a>" +
					"	</div>" +
					"	<div class=\"header_bg_div_title\">" +
					"		<div class=\"back_btn\" onclick=\"javascript:window.history.back();\"><img src=\"../lib/mobile/image/theme2/button_back.png\"><div>返回</div></div>" +
					"		<a class=\"menu_btn\" data-role=\"none\" href=\"mobile-deptOnline.html\">往期回顾</a>" +
					"	</div>" +
					"</div>");
	}
	$div.appendTo($headerDiv);
}

/*
*	组织底部导航栏的显示（非菜单列表页面，即热线聚焦等）
*	footerBarDivId : 底部导航栏DIV的ID
*/
function showFooterBar(footerBarDivId)
{
	//底部导航栏DIV
	var footerBar = $("#" + footerBarDivId);
	
	//清空滚屏列表显示数据
   	footerBar.empty();
   	var menuList = eval(window.menuMap.menuList);//工具菜单
   	var arg = ["a","b","c","d"];
   	
   	//判断是否是当前菜单
   	var select;
	for(var i = 0;i < menuList.length ;i++){
   		var menu = menuList[i];
   		//判断是否是当前菜单
   		select = "0";
   		if(window.menuCode == menu.code){
  			select = "1";
   		}
   		
		var bar = $("<div class=\"ui-block-" + arg[i] + (select == "1" ? " bar_select" : "") + "\" onclick=\"window.menuCode='" + menu.code 
			+ "';$.mobile.changePage('../" + menu.url + "')\">"
			+ "<img src=\"../lib/mobile/image/theme2/" + (select == "1" ? "checked/" : "unchecked/") + menu.image + "\"><span class=\"jszx-bar-text\">" + menu.name + "</span></div>");
		bar.appendTo(footerBar);
	}
	
	select = "0";
	if(window.menuCode == "menu_more"){
 		select = "1";
  	}
	var bar = $("<div class=\"ui-block-e" + (select == "1" ? " bar_select" : "") + "\" onclick=\"window.menuCode='menu_more';$.mobile.changePage('../theme/mobile-menu-more.html')\">"
				+ "<img src=\"../lib/mobile/image/theme2/" + (select == "1" ? "checked/" : "unchecked/") + "gd.png\"><span class=\"jszx-bar-text\">更多</span></div>");
	bar.appendTo(footerBar);
}

/*
*	显示各功能列表的头部标题名称
*   titleID  : 头部标题名称标签ID
*/
function showMenuFunctionTitle(titleID)
{
	//显示菜单功能名称
	if(window.menuFunction != null)
	{
		$("#" + titleID).find("[name='mobileHeaderTitle']").text(window.menuFunction.FUNCTION_NAME);
	}
}

function formatMapObj(obj){
	for(var key in obj){
		obj[key] = obj[key] == "null" 
			|| obj[key] == null || typeof(obj[key]) == "undefined" || obj[key] == "undefined" ? "" : obj[key];
	}
	return obj;
}

//选中checkbox
function checkBox($boxDiv,$checkbox,checkFun){
	$boxDiv.find("label").addClass("ui-btn-active");

	var checxbox = $boxDiv.find(".ui-icon-checkbox-off");
	checxbox.removeClass("ui-icon-checkbox-off");
	checxbox.addClass("ui-icon-checkbox-on");
	$boxDiv.find("label").attr("style","border: 1px solid #F97316;background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0,#FEA467),color-stop(1,#FC8A1B));");
	if(typeof checkFun == "function"){
		checkFun.call();
	}
}

//取消选中checkbox
function uncheckBox($boxDiv,$checkbox,uncheckFun){
	$boxDiv.find("label").removeClass("ui-btn-active");
	
	var checxbox = $boxDiv.find(".ui-icon-checkbox-on");
	checxbox.removeClass("ui-icon-checkbox-on");
	checxbox.addClass("ui-icon-checkbox-off");
	$boxDiv.find("label").attr("style","");
	if(typeof uncheckFun == "function"){
		uncheckFun.call();
	}
}

//加载等待页面
function showLoadPage(content){
	if(content != null && typeof content != "undefined"){
		$("#loginWait").find("#load_img").css("margin","5% 20% 0 20%");
		$("#loginWait").find("#load_content").css("display","");
		$("#loginWait").find("#load_content").html(content);
	}else{
		$("#loginWait").find("#load_img").css("margin","12% 20% 0 20%");
		$("#loginWait").find("#load_content").css("display","none");
		$("#loginWait").find("#load_content").html("");
	}
	$("#loginWait").show();
}

//完成加载页面
function hideLoadPage(){
	$("#loginWait").hide();
	$("#loginWait").find("#load_img").css("margin","12% 20% 0 20%");
	$("#loginWait").find("#load_content").css("display","none");
	$("#loginWait").find("#load_content").html("");
}

var indexObj = new Object();

/**
*  	提示框
*   status  : 提示框类型 0：确定返回 1：是否提示框
*	message ： 提示的内容
*	func ： 是否提示框 '是'时回调函数
*/
indexObj.showMsgDialog = function(status,message,func){
	//显示了提示框
	window.isShowMsgDialog = true;
	$("#indexMsg").show();
	
	setTimeout(function(){
		$("#index_showBox").find(".msgbox").addClass("alert-box-anim");
	}, 10);
	
	var $btnarea = $("#indexMsg").find(".btnarea");
	$btnarea.empty();
	
	//提示显示信息
	$btnarea.html(message);
	var $btn = $("#indexMsg").find(".btn");
	//确认提示框
	if(status == "0"){
		$btn.html("");
		var $btn_ok = $("<div class=\"div_login\" align=\"center\">"+
							"<div>确定</div>"+
						"</div>");
		$btn.append($btn_ok);
		
		$btn_ok.click(function(arg){ 
	      	return function(){
	      		indexObj.hideMsgDialog(arg);
	      	}
	    }(func));
	}
	//确认是否提示框
	else if(status == "1"){
		$btn.html("<table><tr><td></td><td></td></tr></table>");
		var $btn_ok = $("<div class=\"div_login\" align=\"center\">"+
							"<div>确定</div>"+
						"</div>");
		var $btn_cancel = $("<div class=\"div_login\" align=\"center\" onclick=\"indexObj.hideMsgDialog()\">"+
							"<div>取消</div>"+
						"</div>");
		$btn.find("table td:first-child").append($btn_ok);
		$btn.find("table td:last-child").append($btn_cancel);
		$btn_ok.click(function(arg){ 
	      	return function(){
		 		if(typeof arg == "function"){
		 			indexObj.hideMsgDialog();
		 			arg.call();
		 		}
	      	}
	    }(func));
	}
}

//影藏消息提示框
indexObj.hideMsgDialog = function(func){
	window.isShowMsgDialog = false;
	
	$("#index_showBox").find(".msgbox").addClass("alert-box-anim-out");
	setTimeout(function(){
		$("#indexMsg").hide();
		$("#index_showBox").find(".msgbox").removeClass("alert-box-anim");
		$("#index_showBox").find(".msgbox").removeClass("alert-box-anim-out");
	}, 250);
	if(typeof func == "function"){
		func.call();
	}
}

//连接服务器超时
function connectionFail(){
	//结束等待
	hideLoadPage();
	
	indexObj.showMsgDialog("0","连接服务器超时！");
}

function formatDate(date){
	var formatDate = new Date(date);
	var month = formatDate.getMonth()+1;
	var day = formatDate.getDate();
	return formatDate.getFullYear() + "-" + (month < 10 ? ("0" + month) : month) + "-" + (day < 10 ? ("0" + day) : day);
}

function formatTime(date){
	var formatTime = new Date(date);
	var hours = formatTime.getHours();
	var minutes = formatTime.getMinutes();
	var seconds = formatTime.getSeconds();
	return (hours < 10 ? ("0" + hours) : hours) + ":" + (minutes < 10 ? ("0" + minutes) : minutes) + ":" 
		+ (seconds < 10 ? ("0" + seconds) : seconds);
}
